package com.javabase;

import java.util.Arrays;

/**
 * @Description: java类作用描述
 * @Author: Bsea
 * @CreateDate: 2019/6/12$ 21:26$
 */
public class Test11 {
    public static void main(String[] args) {
//        System.out.println(Test11.reverse("abcd"));
//        System.out.println(Test11.reverse2("abcd"));
        System.out.println(Test11.reverse4("abcd"));
    }
    public static String reverse(String s){
        String rs="";
        char[] ss=s.toCharArray();
        for(int i=0;i<ss.length;i++){
            rs=ss[i]+rs;
//            rs=rs+ss[ss.length-1-];
        }
        return rs;
    }


    public static String reverse2(String s){
        StringBuffer rs=new StringBuffer(s);
        return rs.reverse().toString();
    }





    public static String reverse4(String s){
        int n = s.length() - 1;
        char[] value=s.toCharArray();
        for (int j = (n-1) >> 1; j >= 0; j--) {
            int k = n - j;
            char cj = value[j];
            char ck = value[k];
            value[j] = ck;
            value[k] = cj;

        }

        return new String(value);


    }

}
